﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using TomShane.Neoforce.Controls;

namespace SpaceInvade
{
    public static class LevelReader
    {
        private static Manager Manager;
        public static void InitLevelReader(Manager manager)
        {
            Manager = manager;
        }

        public static void ImportXMLData(string fileName, int currentLevel, ref List<Ships.Ship> TheShips)
        {
            //Open the XML document containing level design information
            //Level XML files located in SpaceInvade solution under XML folder
            //Each xml filename should follow the pattern "Level" number ".xml" where number is the level number
            XmlDocument doc = new XmlDocument();
            doc.Load(fileName);

            ImportObjects(ref TheShips, ref doc);
        }

        private static void ImportObjects(ref List<Ships.Ship> _TheShips, ref XmlDocument document)
        {
            int shipX = 0;
            int shipY = 0;
            // start the list off with Player elements
            XmlNodeList objectsList = document.GetElementsByTagName("Enemy1");

            //read data in player nodes
            foreach (XmlNode node in objectsList)
            {
                XmlElement objectElement = (XmlElement)node;
                shipX = Convert.ToInt32(objectElement.GetElementsByTagName("x")[0].InnerText);
                shipY = Convert.ToInt32(objectElement.GetElementsByTagName("y")[0].InnerText);

                _TheShips.Add(new Ships.EnemyShip1(Manager, shipX, shipY, Color.Red));
            }
        }
    }
}
